package com.hp.dao;

import com.hp.entity.Department;
import com.hp.entity.dto.UserDto;
import com.hp.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class DepartmentDao {
    public Department getDepartmentById(Integer departmentId) {
        QueryRunner queryRunner=new QueryRunner(JDBCUtils.getDataSource());
        String sql="SELECT d.id,d.name,d.created_time AS createdTime,d.updated_time AS updatedTime FROM department AS d WHERE id=?";
        try {
            return queryRunner.query(sql,new BeanHandler<Department>(Department.class),departmentId);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
